package com.ohs.ohsoa.system.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.ohs.ohsoa.system.dto.RoleRouterDto;
import com.ohs.ohsoa.system.dto.RouterDto;
import com.ohs.ohsoa.system.entity.RoleRouter;
import com.ohs.ohsoa.system.entity.Router;
import com.ohs.ohsoa.system.service.RouterService;
import com.ohs.ohsoa.system.vo.RouterVo;
import com.ohs.ohsoa.utils.auth.UserLoginToken;
import com.ohs.ohsoa.utils.bean.requestBean.PageParam;
import com.ohs.ohsoa.utils.bean.responseBean.ResultBean;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * 页面Controller
 *
 * @author qianjp
 *
 */

@Api(value = "页面管理", tags = "页面管理")
@RestController
@RequestMapping("/router")
public class RouterController {

	@Resource
	private RouterService routerService;

	/**
	 * 获取页面列表信息  分页
	 *
	 * @param pageParam 检索用参数
	 * @return 页面列表信息
	 *
	 */
	@UserLoginToken
	@PostMapping(value = "/select/list")
	@ApiOperation(httpMethod = "POST", value = "获取页面列表信息")
	public ResultBean<PageInfo<Router>> routerSelectList(@RequestBody PageParam<Router> pageParam) {
		List<Router> res = routerService.routerSelectList(pageParam);
		return ResultBean.success(new PageInfo<>(res));
	}

	/**
	 * 获取页面列表信息
	 *
	 * @param router 页面列表信息数据
	 * @return 页面列表信息
	 *
	 */
	@UserLoginToken
	@PostMapping(value = "/all/list")
	@ApiOperation(httpMethod = "POST", value = "获取页面列表信息")
	public ResultBean<List<RouterVo>> routerAllList(@RequestBody Router router) {
		return ResultBean.success(routerService.routerAllList(router.getGroupEnterpriseGuid()));
	}



	/**
	 * 根据id获取页面详细信息
	 *
	 * @param router 页面详细信息数据
	 * @return 页面详细信息
	 *
	 * departGuid必传
	 */
	@UserLoginToken
	@PostMapping(value = "/select")
	@ApiOperation(httpMethod = "POST", value = "根据id获取页面详细信息")
	public ResultBean<Router> routerSelect(@RequestBody Router router) {
		return ResultBean.success(routerService.routerSelect(router));
	}


	/**
	 * 新增页面
	 *
	 * @param router 新增页面数据
	 * @return 新增结果
	 */
	@UserLoginToken
	@PostMapping(value = "/insert")
	@ApiOperation(httpMethod = "POST", value = "新增页面")
	public ResultBean<Boolean> routerInsert(@RequestBody @Valid Router router, BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
		}
		return ResultBean.success(routerService.routerInsert(router));
	}


	/**
	 * 删除页面
	 *
	 * @param routerDto 删除页面数据
	 * @return 删除结果
	 */
	@UserLoginToken
	@DeleteMapping(value = "/delete")
	@ApiOperation(httpMethod = "DELETE", value = "删除页面")
	public ResultBean<Boolean> routeDelete(@RequestBody RouterDto routerDto) {
		return ResultBean.success(routerService.routeDelete(routerDto));
	}


	/**
	 * 修改页面信息
	 *
	 * @param router 页面信息数据
	 * @return 修改结果
	 */
	@UserLoginToken
	@PutMapping(value = "/update")
	@ApiOperation(httpMethod = "PUT", value = "修改页面信息")
	public ResultBean<Boolean> routerUpdate(@RequestBody @Valid Router router,BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
		}
		return ResultBean.success(routerService.routerUpdate(router));
	}


	/**
	 * 页面与职务之间的关联
	 *
	 * @param RoleRouter 页面与职务之间关联数据
	 * @return 页面与职务之间关联
	 */
	@UserLoginToken
	@PostMapping(value = "/role-router/list")
	@ApiOperation(httpMethod = "POST", value = "页面与职务之间的关联")
	public ResultBean<List<RoleRouter>> RoleRouterList(@RequestBody RoleRouter RoleRouter) {
		return ResultBean.success(routerService.RoleRouterList(RoleRouter));
	}

	/**
	 * 修改 页面与职务之间的关联
	 *
	 * @param roleRouterDto 页面与职务之间的关联数据
	 * @return 修改结果
	 */
	@UserLoginToken
	@PutMapping(value = "/role-router/update")
	@ApiOperation(httpMethod = "PUT", value = "修改 页面与职务之间的关联")
	public ResultBean<Boolean> RoleRouterUpdate(@RequestBody RoleRouterDto roleRouterDto) {
		return ResultBean.success(routerService.RoleRouterUpdate(roleRouterDto));
	}

	/**
	 * 获取父级页面列表信息
	 *
	 * @param router 页面数据
	 * @return 父级页面列表信息
	 *
	 */
	@UserLoginToken
	@PostMapping(value = "/parent-router/list")
	@ApiOperation(httpMethod = "POST", value = "获取父级页面列表信息")
	public ResultBean<List<Router>> parentrouterList(@RequestBody Router router) {
		return ResultBean.success(routerService.parentRouterList(router.getGroupEnterpriseGuid()));
	}

	/**
	 * 获取子级页面列表信息
	 *
	 * @param router 页面数据
	 * @return 子级页面列表信息
	 *
	 */
	@UserLoginToken
	@PostMapping(value = "/children-router/list")
	@ApiOperation(httpMethod = "POST", value = "获取子级页面列表信息")
	public ResultBean<List<Router>> childrenRouterList(@RequestBody Router router) {
		return ResultBean.success(routerService.childrenRouterList(router.getRouterGuid()));
	}

}
